<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <title>amis demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link rel="stylesheet" href="./jssdk/sdk.css" />
    <link rel="stylesheet" href="./jssdk/helper.css" />
    <link rel="stylesheet" href="./jssdk/iconfont.css" />
    <style>
        html,
        body,
        .root {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <div id="root" class="app-wrapper"></div>
    <script src="./jssdk/sdk.js"></script>
    <script type="text/javascript">
        (function () {
            let amis = amisRequire('amis/embed');
            // 通过替换下面这个配置来生成不同页面

            let amisJSON = {
                "type": "page",
                "body": [
                    //start只能用在顶层
                    // {
                    //     type: 'tpl',
                    //     tpl: '${start}'
                    // },

                    {
                        "type": "service",
                        "api": "http://localhost:3000/api/hello?name=John&age=30",
                        "method": "get",
                        // "dataProvider": "setData({ now: new Date().toString() })",

                        "body": [{
                            "type": "tpl",
                            "tpl": "当前日期是：${name}",
                        },
                        {
                            "type": "tpl",
                            "tpl": "请求耗时: ${amisUser.name} ms" // 显示请求耗时
                        }],
                        // "onQuery": {
                        //     "start": "window.startTime = new Date().getTime();",  // 请求开始时记录时间
                        //     "end": "window.endTime = new Date().getTime(); window.elapsedTime = window.endTime - window.startTime;"  // 请求结束时计算耗时
                        // }
                    }
                ]
            }

            // let amisJSON = {
            //     "type": "page",
            //     "body": {
            //         "type": "form",
            //         "api": {
            //             "method": "post",
            //             "url": "http://localhost:3000/api/data",
            //             "headers": {
            //                 "my-header": "aaa"
            //             }
            //         },
            //         "body": [
            //             {
            //                 "type": "input-text",
            //                 "name": "name",
            //                 "label": "姓名："
            //             },
            //             {
            //                 "name": "email",
            //                 "type": "input-email",
            //                 "label": "邮箱："
            //             }
            //         ]
            //     }
            // }
            // 
            let start = new Date().getTime()
            console.log(new Date().getTime())
            let amisScoped = amis.embed('#root', amisJSON, { data: { start: start }, context: {
    amisUser: {
      id: 1,
      name: 'test user'
    }
  } });
            console.log(new Date().getTime())
        })();
    </script>
</body>

</html>